#include "wikiexportdatasetdialog.h"
#include "ui_wikiexportdatasetdialog.h"

#include <QClipboard>
#include <QFileDialog>

WikiExportDataSetDialog::WikiExportDataSetDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WikiExportDataSetDialog)
{
    ui->setupUi(this);
}

WikiExportDataSetDialog::~WikiExportDataSetDialog()
{
    delete ui;
}

void WikiExportDataSetDialog::on_btn_export_copy_clicked()
{
    QClipboard *clipboard = qApp->clipboard();
    clipboard->setText(ui->plain_content->toPlainText());
}


void WikiExportDataSetDialog::on_btn_done_clicked()
{
    accept();
}

void WikiExportDataSetDialog::setTitle(const QString &newTitle)
{
    m_title = newTitle;
}

void WikiExportDataSetDialog::setData(const QString &newData)
{
    m_data = newData;
    ui->plain_content->setPlainText(m_data);
}

void WikiExportDataSetDialog::on_btn_export_file_clicked()
{
    QString filepath = QFileDialog::getSaveFileName(this, "保存到", m_title, "*.json");
    if (filepath.isEmpty()) return;

    QFile file(filepath);
    file.open(QFile::WriteOnly);
    file.write(ui->plain_content->toPlainText().toUtf8());
    file.close();
}
